﻿@using Microsoft.Ajax.Utilities
@using NTQOnlineExam.Services.EntityFW.Entity
@using NTQOnlineExam.Services.Infrastructure.MVC
@using NTQOnlineExamFrontend.Models
@model NTQOnlineExamFrontend.Models.TermInfoViewModel

@{
    ViewBag.Title = this.LocalResources("PageTitle");
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/ContentNew/css/tooltip/tooltipster.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/jquery.tooltipster.min.js")"  type="text/javascript"></script>

<div class="row">
    @foreach (var term in Model.TermByYear)
    {
        var totalQuestion = Model.Sections.Where(x => x.TermId == term.TermId).Sum(x => x.TotalQuestion);
      
        <div class="col-sm-4">
            <div class="pricing-option">
                <div class="pricing-inner">
                    <div class="pricing-header">
                        @if (term.ExpiryDays.HasValue)
                        {
                            <div class="text-muted">Expires after<strong> @term.ExpiryDays</strong> days</div>
                        }
                        else
                        {
                            <div class="text-muted">&nbsp;</div>
                        }
                        <div style="clear: both;">
                            <a href="@Url.RouteUrl(new { Controller = "Term", Action = "GetTermDetail", termId = term.TermId, year = Request["year"] })">
                                <h5>@term.TermName</h5>
                                <span>(@totalQuestion @this.LocalResources("Questions"))</span>
                            </a>
                        </div>
                    </div>
                    <div class="pricing-number">
                        @if (term.Price.HasValue)
                        {
                            @term.Price.Value.ToString("#.## AUD");
                        }
                    </div>
                    <div class="pricing-body">
                        <ul class="list-style-none margin-bottom-0">
                            @{
                                var sections = Model.Sections.Where(x => x.TermId == term.TermId && x.TotalQuestion > 0).ToList();
                            }
                            @foreach (var temp in sections.Take(3))
                            {
                                <li>
                                    @temp.SectionName<br />
                                    <span class="question">@temp.TotalQuestion  @this.LocalResources("Questions")</span>
                                </li>
                            }
                        </ul>
                         @if (sections.Count > 3)
                            {
                                <div class="more-text">@this.LocalResources("AndMoreText")</div>
                            }
                        @if (sections.Count > 0)
                        {
                            <div class="tooltip-content">
                                <strong>Available Sections</strong>
                                <ul>
                                    @foreach (var temp in sections)
                                    {
                                        <li>
                                            @temp.SectionName<br />
                                            <span class="question">@temp.TotalQuestion  @this.LocalResources("Questions")</span>
                                        </li>
                                    }
                                </ul>
                            </div>
                        }
                    </div>
                    <div class="margin-bottom-20">
                        @if (term.IsPaid)
                        {
                            <a class="btn btn-sm btn-blue" style="cursor: not-allowed; width: 90px;" href="#" onclick="return false;">@this.LocalResources("PurchasedButton")</a>
                        }
                        else
                        {
                            <button class="btn btn-sm  btn-red" onclick="BasketClient.AddToBasket(@term.TermId);"><i class="fa fa-shopping-cart"></i>&nbsp;@this.LocalResources("AddToCartButton")</button>
                        }
                    </div>
                </div>
            </div>
        </div>
    }
</div>
@{
    var pagingModel = new PagingModel
    {
        PageCount = Model.PageCount,
        SelectedPage = Model.SelectedPage,
        Href = Url.RouteUrl(new { Controller = "Term", Action = "GetTerms", year = Request["year"] })
    };
    Html.RenderPartial("_Paging", pagingModel);
}
<script type="text/javascript">
    $(document).ready(function () {
        BasketClient.SetAddToBasketUrl('@Url.RouteUrl(new { Controller = "Basket", Action = "AddToBasket" })');

        jQuery.each($('div.pricing-body'), function (i, val) {
            var tooltip = $(this).find('div.tooltip-content');
            if ($(tooltip).length > 0) {
                $(this).tooltipster({
                    content: $(tooltip).html(),
                    contentAsHTML: true,
                    position: 'right',
                    positionTracker: true,
                });
            }
        });

    });
</script>
